<?php
namespace Admin\Controller;
use   Think\Controller;
class LoginController extends Controller{

	public function login() {
     $this->display();
	}

	public function  dologin(){
      $condition=array(
         'adminname'=>$_POST['adminname'],
         'password'=>md5(I('post.password'))
      	);
      $adminModel=M('admins');
      $admin=$adminModel->where($condition)->find();
      if ($admin) {
      	// 是合法用户,设置session值
      	session('admin',$admin);
     	$this->redirect('Index/index');
      }
      else
      {
      	// 非法用户
      	$this->error('用户名与密码不匹配!!!');
      }
	}

	public function  logout(){
        session('admin',null);
        $this->redirect('login');
	}


  public function doupdatePass()
  {
     $condition=array(
         'adminname'=>$_POST['adminname'],
         'password'=>md5(I('post.password1'))
        );
      $adminModel=M('admins');
      $adminModel->create();
      if ($admin=$adminModel->where($condition)->find()) 
      {
      if ($_POST['password']=$_POST['password2'])
        {
          $id=session('admin.adminid');
          $data['password']=md5($_POST['password']);
      if ($adminModel->where('adminid='.$id)->save($data))
       {
        $this->success('修改成功','Login/login');
      }else
        $this->error('修改失败');
    } 
    else
    $this->error('账号密码不匹配','Login/updatePass');
  }  
}
}
?>